﻿using GalaSoft.MvvmLight.Messaging;
using OneOfAll.Common.Bussiness;
using OneOfAll.Common.Models;
using OneOfAll.ViewModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace OneOfAll
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        double mouseWheelStep = 1.2;

        public MainWindow()
        {
            InitializeComponent();
            //Random rd = new Random(Guid.NewGuid().GetHashCode());


            //int width = 128;
            //int height = 128;

            ////byte[,] Matrix = new byte[width, height];
            //Node[,] nodeList = new Node[width, height];
            //for (int x = 0; x < width; x++)
            //{
            //    for (int y = 0; y < height; y++)
            //    {
            //        //if ((x == 0 && y == 0) || (x == width - 1 && y == height - 1))
            //        //{
            //        //    nodeList[x, y] = new Node(x, y, true);
            //        //    Matrix[x, y] = 0;
            //        //}
            //        //else
            //        //{
            //        //    nodeList[x, y] = new Node(x, y, rd.NextDouble() > 0.95 ? true : false);
            //        //    Matrix[x, y] = rd.NextDouble() > 0.9 ? (byte)0 : (byte)1;
            //        //}
            //        if (y == height / 6 && x < width - 1)
            //        {
            //            nodeList[x, y] = new Node(x, y, false);
            //            //Matrix[x, y] = 0;
            //        }
            //        else if (y == height / 2 && x > 0)
            //        {
            //            nodeList[x, y] = new Node(x, y, false);
            //            //Matrix[x, y] = 0;
            //        }
            //        else
            //        {
            //            nodeList[x, y] = new Node(x, y, true);
            //            //Matrix[x, y] = 1;
            //        }

            //        //nodeList[x, y] = new Node(x, y, true);
            //        //Matrix[x, y] = 1;
            //    }
            //}
            //Stopwatch mySw = new Stopwatch();
            //mySw.Start();
            //int time = 10;
            //while (time-- > 0)
            //{
            //    PathHelper ph = new PathHelper(nodeList);
            //    var myResult = ph.FindPath(new Node(0, 0, true), new Node(width - 1, height - 1, true));
            //}
            //mySw.Stop();
            //double myMs = mySw.ElapsedMilliseconds / 10;
            //string sss = myMs.ToString();

            //IPathFinder PathFinder;
            //PathFinder = new PathFinder(Matrix);
            ////PathFinder.Diagonals = false;
            //PathFinder.Formula = HeuristicFormula.Manhattan; //
            //Dictionary<int, List<PathFinderNode>> dic = new Dictionary<int, List<PathFinderNode>>();
            //Stopwatch stopwatch = new Stopwatch();
            //stopwatch.Start();

            //System.Drawing.Point start = new System.Drawing.Point(0, 0);
            //System.Drawing.Point end = new System.Drawing.Point(width - 1, height - 1);
            //List<PathFinderNode> path = PathFinder.FindPath(start, end); //
            //stopwatch.Stop();
            //double usedMs = stopwatch.ElapsedMilliseconds;
        }

        private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.Up:
                case Key.W:
                case Key.Down:
                case Key.S:
                case Key.Left:
                case Key.A:
                case Key.Right:
                case Key.D:
                    Messenger.Default.Send(e.Key, Global.GlobalResource.CameraMove_City);
                    e.Handled = true;
                    break;
            }
        }

        private void self_Loaded(object sender, RoutedEventArgs e)
        {
            Global.GlobalResource.ArchiveInfo = Global.GlobalResource.ArchiveList.FirstOrDefault();
            if (Global.GlobalResource.ArchiveInfo == null)
            {
                Global.GlobalResource.ArchiveInfo = DataCenterManager.Instance.GetNewArchive();
            }
        }
    }
}
